/*     */ package btsm.servlet;
/*     */ 
/*     */ import btsm.bean.sysPro;
/*     */ import java.io.BufferedInputStream;
/*     */ import java.io.BufferedOutputStream;
/*     */ import java.io.ByteArrayOutputStream;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.io.PrintWriter;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ 
/*     */ public class Download extends HttpServlet
/*     */ {
/*  18 */   private final String ENCODING = "UTF-8";
/*     */ 
/*  20 */   private final String CONTENT_TYPE = "text/html;charset=UTF-8";
/*     */ 
/*  22 */   private String downloadfiledir = "";
/*     */ 
/*  24 */   public void init() throws ServletException { sysPro sPro = new sysPro();
/*  25 */     this.downloadfiledir = (sPro.getUploadpath() + "writeexcel/");
/*     */   }
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  31 */     request.setCharacterEncoding("UTF-8");
/*  32 */     response.setContentType("text/html;charset=UTF-8");
/*     */ 
/*  34 */     String[] filearr = { "bts.xls", "B级防雷器.xls", "交直流配电.xls", "交通状况.xls", "传输.xls", "动换监控.xls", "变压器.xls", "固定式油机发电机组.xls", "基站供电归属及外聘发电人员联系电话.xls", "基站地理环境.xls", "塔放.xls", "天馈系统.xls", "市电引入.xls", "机房情况.xls", "灭火器.xls", "电源柜.xls", "空调.xls", "蓄电池.xls", "铁塔.xls" };
/*     */ 
/*  38 */     String fileindex = request.getParameter("fileindex");
/*  39 */     String filename = null;
/*     */ 
/*  41 */     if ((fileindex != null) && (fileindex.matches("^[0-9]*$"))) {
/*  42 */       int iFilname = Integer.parseInt(fileindex);
/*  43 */       if (iFilname < 19) {
/*  44 */         filename = filearr[iFilname];
/*     */       }
/*     */     }
/*  47 */     if ((filename == null) || (filename.trim().equals("")))
/*     */     {
/*  50 */       PrintWriter out = response.getWriter();
/*  51 */       out.println("<font color=red>输入的文件名无效！</font>");
/*  52 */       out.close();
/*     */     }
/*     */     else
/*     */     {
/*  56 */       String fullfilename = this.downloadfiledir + filename;
/*     */ 
/*  58 */       System.out.println("下载文件：" + fullfilename);
/*     */ 
/*  62 */       String contentType = getServletContext().getMimeType(fullfilename);
/*     */ 
/*  64 */       if (contentType == null) {
/*  65 */         response.setContentType("application/octet-stream; charset=UTF-8");
/*     */       }
/*     */ 
/*  70 */       response.setHeader("Content-disposition", "attachment;filename=" + new String(filename.getBytes("gb2312"), "iso8859-1"));
/*  71 */       InputStream is = null;
/*  72 */       OutputStream os = null;
/*     */       try
/*     */       {
/*  75 */         is = new BufferedInputStream(new FileInputStream(fullfilename));
/*     */ 
/*  78 */         ByteArrayOutputStream baos = new ByteArrayOutputStream();
/*     */ 
/*  81 */         os = new BufferedOutputStream(response.getOutputStream());
/*     */ 
/*  84 */         byte[] buffer = new byte[4096];
/*     */ 
/*  86 */         int read = 0;
/*     */ 
/*  88 */         while ((read = is.read(buffer)) != -1) {
/*  89 */           baos.write(buffer, 0, read);
/*     */         }
/*     */ 
/*  93 */         os.write(baos.toByteArray());
/*     */       }
/*     */       catch (IOException e)
/*     */       {
/*  97 */         e.printStackTrace();
/*     */       }
/*     */       finally
/*     */       {
/* 103 */         if (os != null) {
/* 104 */           os.close();
/*     */         }
/* 106 */         if (is != null)
/* 107 */           is.close();
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public void doPost(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/* 117 */     doGet(request, response);
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     btsm.servlet.Download
 * JD-Core Version:    0.6.2
 */